﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DropBoxTool.Model;
using Microsoft.Phone.Controls;

namespace DropBoxTool
{
    public partial class Login : ViewModelPageClassWithQuery
    {
        public Login()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            LoginButton.IsEnabled = false;
            DropBoxController.Inst.Api.LoginAndGetAuthCredentials(emailAddress.Text, password.Password, (result, ex) =>
            {
                if (ex == null && result)
                {
                    var uri = new Uri("/BrowseFiles.xaml", UriKind.Relative);
                    if (!string.IsNullOrEmpty(query))
                    {
                        uri = new Uri("/BrowseFiles.xaml?" + query, UriKind.Relative);
                    }
                    Dispatcher.BeginInvoke(() => NavigationService.Navigate(uri));
                }
                else
                {
                    LoginLog.Text = "Login Failed";
                    LoginButton.IsEnabled = false;
                }
            });
        }
    }
}